package com.baidu.fenfayun.demo.home

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout

import com.qmuiteam.qmui.widget.QMUITopBar
import com.baidu.yun.gameline.R
import com.baidu.fenfayun.demo.base.BaseFragment
import com.baidu.fenfayun.demo.AboutFragment

import android.app.*
import kotlin.collections.List

import kotlin.reflect.*
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import org.jetbrains.anko.support.v4.find
/**
 * @date 2016-10-20
 */

abstract class LayoutController(context:Context,id:Int) :FrameLayout(context) {


   var mHomeControlListener:LayoutControlListener? = null

   init{
      LayoutInflater.from(context).inflate(id, this)
      initView()

   }

   open   fun startFragment(fragment:BaseFragment ) {
      if (mHomeControlListener != null) {
         mHomeControlListener?.startFragment(fragment)
      }
   }

   fun setLayoutControlListener(homeControlListener:LayoutControlListener ) {
      mHomeControlListener = homeControlListener
   }

   abstract fun getTitle():String 

   open fun initView() {

      val topbar = findViewById(R.id.topbar) as QMUITopBar 
      topbar.setTitle(getTitle())
   }
   open fun initAbout() {
      val topbar = findViewById(R.id.topbar) as QMUITopBar 
      topbar.addRightImageButton(R.mipmap.icon_topbar_about, R.id.topbar_right_about_button).setOnClickListener( {
         val fragment = AboutFragment()
         startFragment(fragment)
      })
   }
   open fun getBase():BaseFragment {
      return mHomeControlListener!!.getBase()
   }
   interface LayoutControlListener {
      fun startFragment(fragment:BaseFragment )
      fun getBase():BaseFragment
   }


}
